package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertDataHandleDto;
import com.zzyl.service.AlertDataService;
import com.zzyl.vo.AlertDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description AlertDataController
 * @Author Lwj
 * @Date 2024-09-15-17:04
 */
@RestController
@RequestMapping("/alert-data")
@Api(tags = "报警数据")
@Slf4j
public class AlertDataController {
    @Autowired
    private AlertDataService alertDataService;

    /**
     * 分页查询报警数据
     *
     * @param pageNum
     * @param pageSize
     * @param deviceName
     * @param endTime
     * @param id
     * @param startTime
     * @param status
     * @return
     */
    @GetMapping("/pageQuery")
    @ApiOperation(value = "分页查询报警数据")
    public ResponseResult<PageResponse<AlertDataVo>> pageAlertData(
            @ApiParam(value = "页码") @RequestParam(value = "pageNum", required = true) Long pageNum,
            @ApiParam(value = "页面大小") @RequestParam(value = "pageSize", required = true) Long pageSize,
            @ApiParam(value = "设备名称（精确搜索）") @RequestParam(value = "deviceName", required = false) String deviceName,
            @ApiParam(value = "结束报警时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "报警数据id") @RequestParam(value = "id", required = false) Long id,
            @ApiParam(value = "开始报警时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "状态，0：待处理，1：已处理") @RequestParam(value = "status", required = false) Long status) {
        log.info("分页查询报警数据!");
        PageResponse<AlertDataVo> alertDataVoPageResponse = alertDataService.pageAlertData(pageNum, pageSize, deviceName, endTime, id, startTime, status);
        return ResponseResult.success(alertDataVoPageResponse);
    }

    /**
     * 处理设备报警数据
     *
     * @param id
     * @param alertDataHandleDto
     * @return
     */
    @PutMapping("/handleAlertData/{id}")
    @ApiOperation(value = "处理设备报警数据")
    public ResponseResult handleAlertData(@ApiParam(value = "处理人id") @PathVariable(value = "id", required = true) Long id,
                                          @RequestBody AlertDataHandleDto alertDataHandleDto) {
        log.info("处理设备报警数据!");
        alertDataService.handleAlertData(id, alertDataHandleDto);
        return ResponseResult.success();
    }
}
